package com.yc.dao;

import java.util.List;
import java.util.Map;
/**
 * 查询所有列车
 */
public class AddCarDao {
	public List<Map<String, String>> finds(){
		DBHelper db = new DBHelper();
		String sql = "select c_id,  c_name, c_startstation, c_destination, c_starttime, c_endtime, c_status from tb_train ";
		return db.finds(sql);
	}
	/**
	 * 添加列车
	 * @param type 类型
	 * @param uname 名字
	 * @param startstation 出发站
	 * @param destinaton  终点站
	 * @param starttime   出发时间
	 * @param endtime    到达时间
	 * @return
	 */
	public int add(String type, String uname,String startstation ,String destination, String starttime, String endtime ) {
		DBHelper db = new DBHelper();
		String sql = "insert into tb_train values(seq_train_id.nextval,?,?,0,?,?,?,?)";
		return db.update(sql, type, uname, startstation,destination,starttime,endtime);
	}
	/**
	 * 删除列车
	 * @param cname 列车名字
	 * @return
	 */
	public int delete(String cname) {
		DBHelper db = new DBHelper();
		String sql = "delete from tb_train where c_name = ?";
		return db.update(sql, cname);
	}
	/**
	 * 改变列车的状态 停运  正常
	 * @param status
	 * @param account
	 * @return
	 */
	public int update(int status , String account) {
		DBHelper db = new DBHelper();
		String sql = "update tb_train set c_status = ? where c_name = ?";
		return db.update(sql, status , account);
	}
	/**
	 * 修改列车信息(不包括列车的状态)
	 * @param cname
	 * @param type
	 * @param startstation
	 * @param destination
	 * @param starttime
	 * @param endtime
	 * @param id
	 * @return
	 */
	public int updateTrainInfo( String cname, String type, String startstation, String destination, String starttime, String endtime ,String id) {
		DBHelper db = new DBHelper();
		String sql = "update tb_train set c_name  = ?, c_type = ?, c_startstation = ?, c_destination = ?, c_starttime = ?, c_endtime = ? where c_id = ?";
		return db.update(sql, cname, type, startstation, destination, starttime, endtime , id);
	}
}
